﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using appDataContracts;

namespace appSupplier
{
    /// <summary>
    /// Logique d'interaction pour PasswordWindow.xaml
    /// </summary>
    public partial class PasswordWindow : Window
    {
        public PasswordWindow()
        {
            InitializeComponent();
        }

        private void btCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            if (tbOldPassword.Password != AppWindow.supplier.SUPPLIERPASSWORD)
            {
                lblError.Content = "Ancien mot de passe invalide";
            }
            else if (tbNewPassword.Password != tbConfirm.Password)
            {
                lblError.Content = "Confirmation de mot de passe invalide";
            }
            else if (tbNewPassword.Password.Trim() == "")
            {
                lblError.Content = "Veuillez remplir tous les champs.";
            }
            else
            {
                SerializedSupplier supplier = AppWindow.supplier;
                supplier.SUPPLIERPASSWORD = tbNewPassword.Password;
                AppWindow.supplierService.updateSupplier(supplier);
                this.Close();
            }
        }
    }
}
